*******************************************************************************
* Load data
*******************************************************************************

use dataset_candidates, clear

*******************************************************************************
* Indicator for sampled
*******************************************************************************

gen sampled = !mi(ideology)

*******************************************************************************
* Collapse to district level
*******************************************************************************

collapse population sampled, by(district state)

*******************************************************************************
* Graph
*******************************************************************************

gen lpop = log(pop)
local x lpop

local myxlab
local mytext1
local mytext2
local mytext3

if "`x'" == "lpop" {
	foreach p in 1000 10000 100000 1000000 {
		local lp = log(`p' + 1)
		local p = string(`p', "%20.0fc")
		local myxlab `myxlab' `lp' "`p'"
	}
	local mytext1 text(.225 9 "All Districts", col(black))
	local mytext2 text(0.225 14.75 "{bf:Sampled Districts}", col(black))
}

if "`x'" == "lpop" local mytitle "Population"

#delimit;

gr tw
	(kdensity `x', col(gray) lpat(dash) lcol(black))
	(kdensity `x' if sampled == 1, lwid(thick) lcol(black))
	,
		legend(off)
		plotregion(style(none))
		yscale(off)
		xtitle("Population")
		xlab(`myxlab')
		name(g`x', replace)
		`mytext1'
		`mytext2'
		;
		
#delimit cr
	
*******************************************************************************
* Export
*******************************************************************************

gr export "_output/figure1.pdf", replace
	
*******************************************************************************
* End
*******************************************************************************
